/*

File name		: tableB1.do

Description		: creates table reporting first stages of LATE estimates

Output File		: tableB1.tex
				
*/

set more off, perm
capture restore

*** 001 Analysis/Tabulation ***
use "data/blood_donation/blood_donation.dta", clear

	// Including interactions
	gen phonecall_phonecallminus1=phonecall*phonecall_minus1
	gen phonecallminus1_minus2=phonecall_minus1*phonecall_minus2
	gen phonecallminus2_minus3=phonecall_minus2*phonecall_minus3

// IV of successful phone calls, instrumented with assigned phone calls
// Rename variables temporarily to align in outreg
	rename phonecall* inst_phonecall*
	rename reached* phonecall*
	
	lab var inst_phonecall_phonecallminus1 "Call \$\times\$ Call\$ _{t-1}\$"
	lab var inst_phonecallminus1_minus2 "Call\$ _{t-1}\$ \$\times\$ Call\$ _{t-2}\$"
	lab var inst_phonecallminus2_minus3 "Call\$ _{t-2}\$ \$\times\$ Call\$ _{t-3}\$"
	lab var inst_phonecall_minus1 "Call\$ _{t-1}\$"
	lab var inst_phonecall_minus2 "Call\$ _{t-2}\$"
	lab var inst_phonecall_minus3 "Call\$ _{t-3}\$"
	lab var inst_phonecall "Call\$ _{t}\$"
	
	lab var phonecall_minus1 "Ask \$\times\$ Ask\$ _{t-1}\$"
	lab var phonecall_minus2 "Ask\$ _{t-1}\$ \$\times\$ Ask\$ _{t-2}\$"
	lab var phonecall_minus3 "Ask\$ _{t-2}\$ \$\times\$ Ask\$ _{t-3}\$"
	lab var phonecall "Ask\$ _{t}\$"

	ivreghdfe don male age bltype_dummy2 bltype_dummy3 ///
	(phonecall phonecall_minus1 phonecall_minus2 phonecall_minus3 = inst_phonecall ///
	inst_phonecall_minus1 inst_phonecall_minus2 inst_phonecall_minus3), ///
	cluster(c_num spnr) absorb(c_num) first savefirst
	
	test phonecall_minus1=phonecall_minus2=phonecall_minus3=0
	global kp: di %6.1f `e(widstat)'
	
	estimates restore _ivreg2_phonecall
	outreg2 using output/tables/tableB1, tex replace ///
	drop(male age bltype_dummy2 bltype_dummy3) ///
	ctitle("Ask\$ _{t}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Individual controls, \, Blood drive FE, \, Individual FE, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus1
	outreg2 using output/tables/tableB1, tex append ///
	drop(male age bltype_dummy2 bltype_dummy3) ///
	ctitle("Ask\$ _{t-1}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus2
	outreg2 using output/tables/tableB1, tex append ///
	drop(male age bltype_dummy2 bltype_dummy3) ///
	ctitle("Ask\$ _{t-2}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus3
	outreg2 using output/tables/tableB1, tex append ///
	drop(male age bltype_dummy2 bltype_dummy3) ///
	ctitle("Ask\$ _{t-3}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, $kp, ///
	Individual controls, Y, Blood drive FE, Y, Individual FE, \, ///
	Observations \, `e(N)') noobs
		
	// IDFE
	ivreghdfe don (phonecall phonecall_minus1 phonecall_minus2 ///
	phonecall_minus3=inst_phonecall inst_phonecall_minus1 inst_phonecall_minus2 ///
	inst_phonecall_minus3), ///
	cluster(c_num spnr) absorb(spnr c_num) first savefirst
	
	test phonecall_minus1=phonecall_minus2=phonecall_minus3=0
	global kp: di %6.1f `e(widstat)'
	
	estimates restore _ivreg2_phonecall
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus1
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-1}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus2
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-2}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus3
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-3}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, $kp, ///
	Individual controls, \, Blood drive FE, Y, Individual FE, Y, ///
	Observations \, `e(N)') noobs

	
	gen phonecall_phonecallminus1=phonecall*phonecall_minus1
	gen phonecallminus1_minus2=phonecall_minus1*phonecall_minus2
	gen phonecallminus2_minus3=phonecall_minus2*phonecall_minus3

	gen phone01 = phonecall_phonecallminus1
	gen phone12 = phonecallminus1_minus2
	gen phone23 = phonecallminus2_minus3
	
	ivreghdfe don (phonecall phonecall_minus1 phonecall_minus2 ///
	phonecall_minus3 phone01 phone12 phone23=inst_phonecall*), ///
	cluster(c_num) absorb(spnr c_num) first savefirst
		
	test phone01=phone12=phone23=0
	
	test phonecall_minus1=phonecall_minus2=phonecall_minus3=0
	global kp: di %6.1f `e(widstat)'
	
	estimates restore _ivreg2_phonecall
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus1
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-1}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus2
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-2}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phonecall_minus3
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-3}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phone01
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t}\$ \$ \times \$, Ask\$ _{t-1}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs
	
	estimates restore _ivreg2_phone12
	outreg2 using output/tables/tableB1, tex append ///
	ctitle("Ask\$ _{t-1}\$ \$ \times \$, Ask\$ _{t-2}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, \, ///
	Observations \, `e(N)') noobs 
	
	estimates restore _ivreg2_phone23
	outreg2 using output/tables/tableB1, tex(frag) append label ///
	ctitle("Ask\$ _{t-2}\$ \$ \times \$, Ask\$ _{t-3}\$") ///
	addtext(Joint F-test:, \, \ \ 1\$^{st} \$ stage instruments, $kp, ///
	Individual controls, \, Blood drive FE, Y, Individual FE, Y, ///
	Observations \, `e(N)') noobs 
	
